# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

CXX= g++ -g
TOBJS= main.o HTTPRequest.o HTTPResponse.o Tokenizer.o URL.o  Downloader.o Socket.o
MOBJS = main.o HTTPRequest.o HTTPResponse.o Tokenizer.o URL.o  Downloader.o Socket.o
OBJS = $(TOBJS)


LIBS = -lpthread -lrt

CCFLAGS= -g

all: 	test

test:   $(TOBJS)
	$(CXX) -o test $(TOBJS) $(LIBS)
	
build:	$(TOBJS)
	$(CXX) -o download $(TOBJS) $(LIBS)

run:	build
	./download -n 5 http://ilab.cs.byu.edu/cs360/2012f/scripts/plot.py
	./download -n 5 http://ilab.cs.byu.edu/wp-content/uploads/2012/05/mesh-.png
	./download -n 5 http://carlosmansilla.com/images/Landscapes/Ati.jpg	
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test

test10:	test1-10 test2-10 test3-10 test4-10 test5-10 test6-10 test7-10 test8-10 test9-10 test10-10
	
test100:    test1-100 test2-100 test3-100 test4-100 test5-100 test6-100 test7-100 test8-100 test9-100 test10-100

	
test1-10:    build
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	./download -n 1 http://cachefly.cachefly.net/10mb.test
	
test2-10:    build
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test
	./download -n 2 http://cachefly.cachefly.net/10mb.test

test3-10:    build
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test
	./download -n 3 http://cachefly.cachefly.net/10mb.test

test4-10:    build
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	./download -n 4 http://cachefly.cachefly.net/10mb.test
	
test5-10:    build
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	./download -n 5 http://cachefly.cachefly.net/10mb.test
	
test6-10:    build
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test
	./download -n 6 http://cachefly.cachefly.net/10mb.test

test7-10:    build
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	./download -n 7 http://cachefly.cachefly.net/10mb.test
	
test8-10:    build
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	./download -n 8 http://cachefly.cachefly.net/10mb.test
	
test9-10:    build
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	./download -n 9 http://cachefly.cachefly.net/10mb.test
	
test10-10:    build
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test
	./download -n 10 http://cachefly.cachefly.net/10mb.test

test1-100:    build
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	./download -n 1 http://cachefly.cachefly.net/100mb.test
	
test2-100:    build
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test
	./download -n 2 http://cachefly.cachefly.net/100mb.test

test3-100:    build
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test
	./download -n 3 http://cachefly.cachefly.net/100mb.test

test4-100:    build
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	./download -n 4 http://cachefly.cachefly.net/100mb.test
	
test5-100:    build
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	./download -n 5 http://cachefly.cachefly.net/100mb.test
	
test6-100:    build
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test
	./download -n 6 http://cachefly.cachefly.net/100mb.test

test7-100:    build
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	./download -n 7 http://cachefly.cachefly.net/100mb.test
	
test8-100:    build
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	./download -n 8 http://cachefly.cachefly.net/100mb.test
	
test9-100:    build
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	./download -n 9 http://cachefly.cachefly.net/100mb.test
	
test10-100:    build
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test
	./download -n 10 http://cachefly.cachefly.net/100mb.test


val:	$(TOBJS)
	valgrind -v --leak-check=full --show-reachable=yes ./download -n 5 http://cachefly.cachefly.net/10mb.test

pull:	
	../
	hg pull
	hg update -C
	cd http/

clean:
	rm -f $(OBJS) $(OBJS:.o=.d)

realclean:
	rm -f $(OBJS) $(OBJS:.o=.d) test download


# These lines ensure that dependencies are handled automatically.
%.d:	%.cpp
	$(SHELL) -ec '$(CPP) -M $(CPPFLAGS) $< \
		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
		[ -s $@ ] || rm -f $@'

%.d:	%.cc
	$(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< \
		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
		[ -s $@ ] || rm -f $@'
include	$(OBJS:.o=.d)
